//
//  ActionCourse.m
//  Courses
//
//  Created by xxx on 15/1/7.
//  Copyright (c) 2015年 wtf. All rights reserved.
//

#import "ActionCourse.h"
#import "Request.h"

@implementation ActionCourse

- (id)initWithJsonDict:(NSDictionary *)jsonDict
{
    if (self = [super initWithJsonDict:jsonDict])
    {
        self.photoURL = jsonDict[@"photoURL"];
        self.subjectName = jsonDict[@"subjectName"];
        self.actionURL = jsonDict[@"actionURL"];
    }
    return self;
}

+ (NSArray *)actionCourses
{
    NSMutableArray *actionCourses = [[NSMutableArray alloc] init];
    
    Request *request = [Request requestWithName:@"action"];
    Response *response = [request response];
    
    if (response.result)
    {
        for (id jsonDict in response.content)
        {
            if ([jsonDict isKindOfClass:[NSDictionary class]])
            {
                ActionCourse *course = [[self alloc] initWithJsonDict:jsonDict];
                [actionCourses addObject:course];
            }
        }
    }
    
    return [actionCourses copy];
}

+ (ActionCourse *)currentLiveCourse
{
    ActionCourse *course = nil;
    Request *request = [Request requestWithName:@"live"];
    Response *response = [request response];
    
    if (response.result)
    {
        course = [[self alloc] initWithJsonDict:response.content];
    }
    return course;
}

+ (NSArray *)recommendCourses
{
    NSMutableArray *recommendCourses = [[NSMutableArray alloc] init];
    
    Request *request = [Request requestWithName:@"recommend"];
    Response *res = [request response];
    if (res.result)
    {
        for (id jsonDict in res.content[@"courses"])
        {
            if ([jsonDict isKindOfClass:[NSDictionary class]])
            {
                Course *course = [[self alloc] initWithJsonDict:jsonDict];
                [recommendCourses addObject:course];
            }
        }
    }
    return [recommendCourses copy];
}

@end
